package edu.hunau.recommend.controller.admin;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import edu.hunau.recommend.advice.AdminPermission;
import edu.hunau.recommend.pojo.Category;
import edu.hunau.recommend.pojo.Seller;
import edu.hunau.recommend.pojo.Shop;
import edu.hunau.recommend.request.PageQuery;
import edu.hunau.recommend.request.ShopReq;
import edu.hunau.recommend.service.ShopService;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @author name
 * @creater 2022-09-20-16:37
 */
@Controller
@RequestMapping("/admin/shop")
public class ShopManagerController {

    @Resource
    private ShopService shopService;

    @RequestMapping("/index")
    @AdminPermission
    public ModelAndView index(PageQuery pageQuery){
        //利用PageHelper插件进行分页设置(起始页, 页面大小)
        PageHelper.startPage(pageQuery.getPage(), pageQuery.getSize());
        List<Shop> shops = shopService.selectAll();
        PageInfo<Shop> pageInfo = new PageInfo<>(shops);

        ModelAndView mv = new ModelAndView("/admin/shop/index.html");

        mv.addObject("CONTROLLER_NAME","shop");
        mv.addObject("ACTION_NAME","index");
        mv.addObject("data",pageInfo);

        return mv;


    }
    @RequestMapping("/createpage")
    @AdminPermission
    public ModelAndView createPage(){
        ModelAndView mv=new ModelAndView("/admin/shop/create.html");
        mv.addObject("CONTROLLER_NAME", "shop");
        mv.addObject("ACTION_NAME", "index");
        return mv;
    }

    @RequestMapping("/create")
    public String create(@Valid ShopReq shopReq, BindingResult bindingResult){
        //实现创建的逻辑
        return "redirect:/admin/shop/index";
    }
}
